<template>
	<view class="coach">
		<Singlestore :query="shopQuery"></Singlestore>
		<scroll-view scroll-y="true" class="scroll-view-Y" @scrolltolower="scrolltolower">
			<view class="comlum_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="item" @click="routeItem(item, index)">
					<image :src="$IMG_URL('/static/shop/recommend.png')" mode="aspectFill" class="recommend"></image>
					<Oitem :query="item"></Oitem>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="'门店教练'"></empty>
		</scroll-view>
	</view>
</template>

<script>
	import Singlestore from '../components/Singlestore.vue'
	import Oitem from '@/components/coachItem.vue';
	import empty from '@/components/empty.vue'
	import {
		coach
	} from '@/api/shop.js'

	export default {
		components: {
			Singlestore,
			Oitem,
			empty
		},
		data() {
			return {
				intent: {
					shop_id: '',
					page: 1
				},
				status: 'loadmore', //当前状态
				shopQuery: {},
				list: [],
				loadText: {
					loadmore: '上拉加载',
					loading: '加载中',
					nomore: '到底了'
				}
			}
		},
		onLoad(e) {
			this.intent.shop_id = e.shop_id
			this.getcoach()
		},
		methods: {
			scrolltolower() {
				this.intent.page++
				this.getcoach()
			},
			getcoach() {
				coach(this.intent).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.shopQuery = res.data.shop_info
						const list = res.data.coach_list
						this.status = 'loading'
						if (this.intent.page > res.data.all_Page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.coach_list)
						}

						console.log('list', this.list);
					}
				})
			},
			routeItem(item, index) {
				uni.navigateTo({
					url: 'deatil'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.scroll-view-Y {
		height: 83vh;

		.comlum_box {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 20rpx;

			.item {
				margin-bottom: 20rpx;
				width: 702rpx;
				height: 352rpx;
				background: #ffffff;
				border-radius: 16rpx;
				position: relative;
				padding: 20rpx;

				.recommend {
					position: absolute;
					top: 0;
					right: 0;
					width: 136rpx;
					height: 38rpx;
					z-index: 99;

				}
			}
		}
	}
</style>